function filename = FormatFileName(prefix, suffix, ex, varargin)

filename = prefix;

for i = 1 : length(varargin)
    if isnumeric(varargin{i})
        if length(varargin{i}) == 1
            varargin{i} = num2str(varargin{i});
        else
            varargin{i} = regexprep(['[' num2str(varargin{i}) ']'], '\s*', ',');
        end
    end
    filename = sprintf('%s-%s(%s)', filename, inputname(i+3), varargin{i});
end

if ~isempty(suffix)
    filename = sprintf('%s-%s', filename, suffix);
end
filename = [filename ex];
